/**
 * Copyright (c) 2012 Nokia Corporation.
 */

package com.nokia.example.imagescaler;

import javax.microedition.lcdui.Image;

/**
 * Generic base class for image scalers. The algorithm used in the
 * implementation can vary.
 */
public abstract class ImageScaler {
	/**
	 * Scales the given image and returns a new created scaled image.
	 * @param newWidth The width of the scaled image.
	 * @param newHeight The height of the scaled image.
	 * @param originalImage The original image.
	 * @return The newly created, scaled image.
	 */
	public abstract Image scale(int newWidth, int newHeight, Image originalImage);
	
	/**
	 * For convenience. Scales the given image based on the given size. The size
	 * is expected to be percentages where value 1.0 being the size of the
	 * original image.
	 * @param newSize The new size in percentages compared to the original image
	 *                size.
	 * @param originalImage The original image.
	 * @return The newly created, scaled image.
	 */
	public Image scale(float newSize, Image originalImage) {
		if (originalImage == null) {
			throw new IllegalArgumentException(
					"Error: The given image is null!");
		}
		
		final int width = (int)(originalImage.getWidth() * newSize);
		final int height = (int)(originalImage.getHeight() * newSize);
		
		return scale(width, height, originalImage);
	}
	
	/** 
	 * @return The type or name of this particular image scaler implementation.
	 */
	public abstract String type();
}
